package com.wang.bind;

import java.beans.PropertyEditorSupport;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * @Classname MyCustomDateEditor
 * @Description TODO
 * @Date 2024/5/21 11:09
 * @Created by pc
 */
public class MyCustomDateEditor extends PropertyEditorSupport {

    // 设置 将前端传入的时间戳转换成date类型
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        setValue(new Date(Long.decode(text)));
    }

    // 获取 将date类型转换成字符串（时间戳）
    @Override
    public String getAsText() {
        Date value  = (Date)getValue();
        return value != null ? String.valueOf(TimeUnit.MILLISECONDS.toSeconds(value.getTime()))  :"" ;
    }
}
